Skip to content

[mypyc] Add faster primitive for string equality #19402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 9, 2025
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 8, 2025

This speeds up self check by ~1.4%. String equality is one of the top
five most common primitive function calls in self check.

We previously used a string comparison primitive that calculated the
relative order of two strings. Usually we only care about equality,
which we can do quicker since we can fast path using a length check,
for example.

I checked the CPython implementation of string equality in 3.9 (lowest
supported Python version) and 3.13, and both of them had a fast path
based on string object kind, and equality checks overall had the same
semantics.

Current CPython implementation:
https://github.com/python/cpython/blob/main/Objects/stringlib/eq.h

Tests for this were added in #19401.

JukkaL added 2 commits July 8, 2025 14:28
This speeds up self check by ~1.4%.  String equality is one of the top
five most common primitive function calls in self check.

We previously used a string comparison primitive that calculated the
relative order of two strings. Usually we only care about equality,
which we can do quicker since we can fast path using a length check,
for example.

I checked the CPython implementation of string equality in 3.9 (lowest
supported Python version) and 3.13, and both of them had a fast path
based on string object kind, and equality checks overall have the same
semantics.
@JukkaL JukkaL requested a review from ilevkivskyi July 8, 2025 17:23
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@JukkaL JukkaL merged commit 10f95e6 into master Jul 9, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-str-equal branch July 9, 2025 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants